import 'Util.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebViewPage extends StatefulWidget {
  const WebViewPage({Key? key, required this.title, required this.url})
      : super(key: key);
  final String title;
  final String url;
  @override
  _WebViewPageState createState() => _WebViewPageState();
}

class _WebViewPageState extends State<WebViewPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    UtilLog(widget.title);
    UtilLog(widget.url);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: WebView(
        initialUrl: widget.url,
        //JS执行模式 是否允许JS执行
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (controller) {
          UtilLog("create");
        },
        onPageStarted: (u) {
          UtilLog("start");
          UtilLog(u);
        },
        onPageFinished: (u) {
          UtilLog("finish");
          UtilLog(u);
        },
        onWebResourceError: (e) {
          UtilLog("error:");
          UtilLog(e.description);
        },
      ),
    );
  }
}
